<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>解码已编码的 URL 字符串</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.urldecode" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">urldecode</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">urldecode</span> &mdash; <span class="dc-title">解码已编码的 URL 字符串</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.urldecode-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>urldecode</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$str</code></span>
   ) : <span class="type">string</span></div>

  <p class="para rdfs-comment">
   解码给出的已编码字符串中的任何
   <em>%<span class="replaceable">##</span></em>。
   加号（&#039;<em>+</em>&#039;）被解码成一个空格字符。
   
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.urldecode-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">str</code></dt>

     <dd>

      <p class="para">
       要解码的字符串。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


  <div class="refsect1 returnvalues" id="refsect1-function.urldecode-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回解码后的字符串。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.urldecode-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4896">
    <p><strong>Example #1 <span class="function"><strong>urldecode()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$query&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"my=apples&amp;are=green+and+red"</span><span style="color: #007700">;<br /><br />foreach&nbsp;(</span><span style="color: #0000BB">explode</span><span style="color: #007700">(</span><span style="color: #DD0000">'&amp;'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$query</span><span style="color: #007700">)&nbsp;as&nbsp;</span><span style="color: #0000BB">$chunk</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$param&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">explode</span><span style="color: #007700">(</span><span style="color: #DD0000">"="</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$chunk</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$param</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"Value&nbsp;for&nbsp;parameter&nbsp;\"%s\"&nbsp;is&nbsp;\"%s\"&lt;br/&gt;\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">urldecode</span><span style="color: #007700">(</span><span style="color: #0000BB">$param</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]),&nbsp;</span><span style="color: #0000BB">urldecode</span><span style="color: #007700">(</span><span style="color: #0000BB">$param</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]));<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.urldecode-notes">
  <h3 class="title">注释</h3>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">
    超全局变量  <var class="varname"><var class="varname"><a href="reserved.variables.get.html" class="classname">$_GET</a></var></var> 和 <var class="varname"><var class="varname"><a href="reserved.variables.request.html" class="classname">$_REQUEST</a></var></var> 已经被解码了。对 <var class="varname"><var class="varname"><a href="reserved.variables.get.html" class="classname">$_GET</a></var></var> 或   <var class="varname"><var class="varname"><a href="reserved.variables.request.html" class="classname">$_REQUEST</a></var></var> 里的元素使用 <span class="function"><strong>urldecode()</strong></span> 将会导致不可预计和危险的结果。
   </p>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.urldecode-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="urlencode.html" class="function" rel="rdfs-seeAlso">urlencode()</a> - 编码 URL 字符串</span></li>
    <li class="member"><span class="function"><a href="rawurlencode.html" class="function" rel="rdfs-seeAlso">rawurlencode()</a> - 按照 RFC 3986 对 URL 进行编码</span></li>
    <li class="member"><span class="function"><a href="rawurldecode.html" class="function" rel="rdfs-seeAlso">rawurldecode()</a> - 对已编码的 URL 字符串进行解码</span></li>
    <li class="member"><a href="http://www.faqs.org/rfcs/rfc3986" class="link external">&raquo;&nbsp;RFC 3986</a></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>